package com.sunfeng.two.p2;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import util.ConnectionUtil;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * @Auther: Administrator
 * @Date: 2019/2/26 10:43
 * @Description:
 *
 */
public class Task02 {


    private static final String TASK_QUEUE_NAME = "ack_queue";


    public static void main(String[] args) throws IOException, TimeoutException {
        final Channel channel = ConnectionUtil.getChannel();

        //声明 队列持久化
        channel.queueDeclare(TASK_QUEUE_NAME, true, false, false, null);

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()){
            String message = scanner.next();
            // 消息持久化 配置MessageProperties.PERSISTENT_TEXT_PLAIN
            channel.basicPublish("",TASK_QUEUE_NAME,MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes(StandardCharsets.UTF_8));

            System.out.println("消息发送成功");
        }
    }
}
